package com.shy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shy.config.common.BaseQuery;
import com.shy.config.util.AuthUtils;
import com.shy.entity.Clue;
import com.shy.entity.Customer;
import com.shy.entity.Tran;
import com.shy.mapper.TranMapper;
import com.shy.service.TranService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class TranServiceImpl implements TranService {
    @Resource
    private TranMapper tranMapper;
    @Override
    public PageInfo<Tran> queryTranPageList(Integer current, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(current, pageSize);
        //查询数据
        List<Tran> list = tranMapper.queryTranPageList(new BaseQuery());
        //创建分页对象
        PageInfo<Tran> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Tran queryTranDetailById(Integer tranId) {
        return tranMapper.selectTranById(tranId);
    }

    @Override
    public Boolean modifyTran(Tran tran) {
        tran.setEditBy(AuthUtils.getLoginSecurityUserId());
        tran.setEditTime(new Date());
        return tranMapper.updateByPrimaryKeySelective(tran)>0;
    }

    @Override
    public Boolean deleteTranByIds(List<Integer> tranIds) {
        return tranMapper.batchDeleteByIds(tranIds)>0;
    }

    @Override
    public Boolean saveTran(Tran tran) {
       // 设置创建人
        tran.setCreateBy(AuthUtils.getLoginSecurityUserId());
        tran.setCreateTime(new Date());
        //根据创建时间生成流水号
        tran.setTranNo((new SimpleDateFormat("yyyyMMddHHmmssSSSS").format(new Date())));
        return tranMapper.insertSelective(tran)>0;
    }
}
